﻿using Power.Models;
using Power.View.Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Power.ViewModel.Report
{
    /// <summary>
    /// 管段工作量表
    /// </summary>
    public class SectionWorkLoadTableViewModel : ReportTableBase
    {
        public List<PipnetSegTableData> Data { get; set; }
        private SectionWorkLoadTable model;
        public SectionWorkLoadTableViewModel(SectionWorkLoadTable model)
        {
            this.model = model;
            Data = CreateEntity<PipnetSegTableData>(10);

            Init();
        }

        /// <summary>
        /// 动态创建测试数据
        /// </summary>
        /// <param name="subCount"></param>
        /// <returns></returns>
        public List<T> CreateEntity<T>(int count)
        {
            var list = new List<T>();

            for (int i = 0; i < count; i++)
            {
                var obj = Activator.CreateInstance(typeof(T));

                var type = obj.GetType();
                var props = type.GetProperties();
                foreach (var item in props)
                {
                    if (item.PropertyType == typeof(int))
                    {
                        item.SetValue(obj, 1);
                    }
                    else if (item.PropertyType == typeof(string))
                    {
                        item.SetValue(obj, "2");
                    }
                    else if (item.PropertyType == typeof(double))
                    {
                        item.SetValue(obj,3);
                    }
                }
                list.Add((T)obj);
            }

            return list;
        }
        public void Init()
        {
            var color1 = new SolidColorBrush(Color.FromRgb(0, 0, 255));
            var color2 = new SolidColorBrush(Color.FromRgb(255, 255, 0));
            var color3 = new SolidColorBrush(Color.FromRgb(255, 102, 0));
            var color4 = new SolidColorBrush(Color.FromRgb(255, 0, 0));

            //Row = Data.Count() + 4;
            Row = Data.Count() + 3;
            Column = 17;

            var table = this.model.table;

            for (int i = 0; i < Row; i++)
            {
                table.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });

            }
            for (int i = 0; i < Column; i++)
            {
                table.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(100) });
            }

            //画标题
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < Column; j++)
                {
                    DrawColumnSpanCell(table, i, j, "管段工作量表", Column, 0, 0);


                    DrawRowSpanCell(table, i, j, "片区代码", 2, 1, 0);
                    DrawRowSpanCell(table, i, j, "区块代码", 2, 1, 1);
                    DrawRowSpanCell(table, i, j, "工点名称", 2, 1, 2);
                    DrawRowSpanCell(table, i, j, "起始井号", 2, 1, 3);
                    DrawRowSpanCell(table, i, j, "终止井号", 2, 1, 4);
                    DrawRowSpanCell(table, i, j, "管段类型", 2, 1, 5);
                    DrawRowSpanCell(table, i, j, "管段材质", 2, 1, 6);


                    DrawCell(table, i, j, "管段直径", 1, 7);
                    DrawCell(table, i, j, "管段长度", 1, 8);
                    DrawCell(table, i, j, "检测长度", 1, 9);

                    DrawCell(table, i, j, "mm", 2, 7);
                    DrawColumnSpanCell(table, i, j, "m", 2, 2, 8);

                    DrawRowSpanCell(table, i, j, "检测方法", 2, 1, 10);
                    DrawRowSpanCell(table, i, j, "检测方向", 2, 1, 11);
                    DrawRowSpanCell(table, i, j, "检测日期", 2, 1, 12);
                    DrawRowSpanCell(table, i, j, "检测批次", 2, 1, 13);
                    DrawRowSpanCell(table, i, j, "检测员", 2, 1, 14);
                    DrawRowSpanCell(table, i, j, "分包商", 2, 1, 15);
                    DrawRowSpanCell(table, i, j, "序号", 2, 1, 16);

                    
                    
                }
            }

            //画内容
            var currentRow = 3;
            for (int i = 3; i < Data.Count+3; i++)
            {
                var item = Data[i-3];
                var columnIndex = 0;
                DrawCell(table, currentRow, columnIndex, item.AreaCode, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.BlockCode, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.WorkField, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.StartWellName, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.EndWellName, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.PipeType, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.PipeMate, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.PipeDia.ToString(), currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.PipeLen.ToString(), currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.DetectLen.ToString(), currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.DetecMethod, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.DetectDir, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.DetectTime, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.DetectBatch.ToString(), currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.Inspector, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.Subcontractors, currentRow, columnIndex++);
                DrawCell(table, currentRow, columnIndex, item.Order, currentRow, columnIndex++);

                currentRow++;
            }

            //合计
            //{
            //    var columnIndex = 0;
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "合计", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, Data.Sum(p=>p.PipeLen).ToString(), currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, Data.Sum(p => p.DetectLen).ToString(), currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //    DrawCell(table, currentRow, columnIndex, "-", currentRow, columnIndex++);
            //}
            //补边框
            DrawBorder(table);
        }
    }
}
